﻿package com.sz.login.bmo.impl;

import java.util.HashMap;
import java.util.Map;

import com.sz.login.bmo.ILoginBMO;
import com.sz.login.dao.ILoginDAO;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;




public class LoginBMOImpl implements ILoginBMO{

	public ILoginDAO	loginDAO;
	
	protected final Log logger = LogFactory.getLog(getClass());
	
	public ILoginDAO getLoginDAO() {
		return loginDAO;
	}



	public void setLoginDAO(ILoginDAO loginDAO) {
		this.loginDAO = loginDAO;
	}
	
	/**
	 * 
	 * @param username
	 * @param passwords
	 * @param ip
	 * @return Map.msg==null表示登陆成功
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public Map doLogin(String username, String passwords, String region, String ip) throws Exception{
		logger.info("登陆验证");
		Map r = loginDAO.verifyLogin(username, passwords, region);
				
		if(r.get("MESSAGE") == null) {
			//密码正确  记录登陆信息
			logger.info("记录登陆日志");
			Map param = new HashMap();
			param.put("MANAGER_ID", r.get("MANAGER_ID"));
			param.put("LOGIN_IP", ip);
			loginDAO.logLogin(param);						
		}
		
		return r;		
	}

}
